diff options
| author | Frank <[email protected]> | 2026-01-13 17:51:20 -0500 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-01-13 17:51:21 -0500 |
| commit | eaf18d991576771ccbc3975a6c7a9358b0da8de9 (patch) | |
| tree | 1a5b3e395714502638fbffd55ac7e6b4fe9f0f1b /packages/console/app/src/routes/auth/[...callback].ts | |
| parent | f3d4dd5099003070800cc9ec161877634fdd7c0a (diff) | |
| download | opencode-eaf18d991576771ccbc3975a6c7a9358b0da8de9.tar.gz opencode-eaf18d991576771ccbc3975a6c7a9358b0da8de9.zip | |
wip: black
Diffstat (limited to 'packages/console/app/src/routes/auth/[...callback].ts')
| -rw-r--r-- | packages/console/app/src/routes/auth/[...callback].ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/packages/console/app/src/routes/auth/[...callback].ts b/packages/console/app/src/routes/auth/[...callback].ts new file mode 100644 index 000000000..36a9c5194 --- /dev/null +++ b/packages/console/app/src/routes/auth/[...callback].ts @@ -0,0 +1,41 @@ +import { redirect } from "@solidjs/router" +import type { APIEvent } from "@solidjs/start/server" +import { AuthClient } from "~/context/auth" +import { useAuthSession } from "~/context/auth" + +export async function GET(input: APIEvent) { + const url = new URL(input.request.url) + + try { + const code = url.searchParams.get("code") + if (!code) throw new Error("No code found") + const result = await AuthClient.exchange(code, `${url.origin}${url.pathname}`) + if (result.err) throw new Error(result.err.message) + const decoded = AuthClient.decode(result.tokens.access, {} as any) + if (decoded.err) throw new Error(decoded.err.message) + const session = await useAuthSession() + const id = decoded.subject.properties.accountID + await session.update((value) => { + return { + ...value, + account: { + ...value.account, + [id]: { + id, + email: decoded.subject.properties.email, + }, + }, + current: id, + } + }) + return redirect(url.pathname === "/auth/callback" ? "/auth" : url.pathname.replace("/auth/callback", "")) + } catch (e: any) { + return new Response( + JSON.stringify({ + error: e.message, + cause: Object.fromEntries(url.searchParams.entries()), + }), + { status: 500 }, + ) + } +} |
